﻿using Admin_jiaju.Application.Dtos;
using Admin_jiaju.Application.Students.Dtos;
using Admin_jiaju.Core.Models;
using Admin_jiaju.Core.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;
using System.Collections;

namespace Admin_jiaju.Application.Students
{
    public class Admin_jiajuService : IAdmin_jiajuService
    {
        private readonly IRepository<Banner, int> _repository;
        private readonly IRepository<Product, int> _repositoryProduct;

        public Admin_jiajuService (
            IRepository<Banner, int> repository,
             IRepository<Product, int> repositoryProduct

            )
        {
            _repository = repository;
            _repositoryProduct = repositoryProduct;
        }
        public async Task<PagedResultDto<Banner>> GetPagedResultAsync(StudnetInputDto inputDto)
        {
            var quer =  _repository.GetAll();
            if (!string.IsNullOrEmpty(inputDto.Title))
            {
                quer = quer.Where(t => t.Title.Contains(inputDto.Title));
            }
            var count = quer.Count();
            quer = quer.OrderBy(inputDto.Sorting).Skip((inputDto.Page-1)*inputDto.Limit).Take(inputDto.Limit);
            var stuts =await quer.AsNoTracking().ToListAsync();//AsNoTracking不对实体类进行追踪
            var dtos = new PagedResultDto<Banner>
            {
                TotalCount = count,
                Page = inputDto.Page,
                Limit = inputDto.Limit,
                Data = stuts,
                FilterText = inputDto.FilterText,
                Sorting = inputDto.Sorting
            };
            return dtos;
        }

        //public async Task<PagedResultDto<Product>> GetPageProducyAsync(ProductPageDtos productPageDtos)
        //{
        //    var quer = _repositoryProduct.GetAll();
        //    if (!string.IsNullOrEmpty(productPageDtos.Name))
        //    {
        //        quer = quer.Where(t => t.Name.Contains(productPageDtos.Name));
        //    }
        //    if (!string.IsNullOrEmpty(productPageDtos.XingHao))
        //    {
        //        quer = quer.Where(t => t.XingHao == (productPageDtos.XingHao));
        //    }
        //    if (!string.IsNullOrEmpty(productPageDtos.CaiZhi))
        //    {
        //        quer = quer.Where(t => t.CaiZhi == (productPageDtos.CaiZhi));
        //    }
        //    if (!string.IsNullOrEmpty(productPageDtos.HomeFlag))
        //    {
        //        quer = quer.Where(t => t.HomeFlag == (productPageDtos.HomeFlag));
        //    }
        //    var count = quer.Count();

        //    quer = quer.OrderBy(t => t.Id).Skip((productPageDtos.Page - 1) * productPageDtos.Limit).Take(productPageDtos.Limit);
        //    var stuts = await quer.ToListAsync();//AsNoTracking不对实体类进行追踪
        //    var dtos = new PagedResultDto<Product>
        //    {
        //        TotalCount = count,
        //        Page = productPageDtos.Page,
        //        Limit = productPageDtos.Limit,
        //        Data = stuts,
        //        FilterText = productPageDtos.FilterText,
        //        Sorting = productPageDtos.Sorting
        //    };

        //    return dtos;
        //}
    }
}
